<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>天气预报</title>
    <script src="js/vue.global.js"></script>
    <script src="js/axios.min.js"></script>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            background: linear-gradient(135deg, #72edf2 0%, #5151e5 100%);
            color: #fff;
            min-height: 100vh;
            margin: 0;
            padding: 20px;
        }
        .container {
            max-width: 800px;
            margin: 0 auto;
        }
        .search-box {
            display: flex;
            justify-content: center;
            margin-bottom: 20px;
        }
        input {
            padding: 10px 15px;
            border: none;
            border-radius: 20px 0 0 20px;
            outline: none;
            width: 70%;
        }
        button {
            padding: 10px 20px;
            border: none;
            border-radius: 0 20px 20px 0;
            background: #ff8c00;
            color: white;
            cursor: pointer;
        }
        button:hover {
            background: #ff6b00;
        }
        .current-weather {
            background: rgba(255, 255, 255, 0.2);
            border-radius: 15px;
            padding: 20px;
            margin-bottom: 20px;
            text-align: center;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
        }
        .current-temp {
            font-size: 3rem;
            font-weight: bold;
            margin: 10px 0;
        }
        .weather-icon {
            width: 100px;
            height: 100px;
        }
        .forecast {
            display: flex;
            overflow-x: auto;
            gap: 15px;
            padding-bottom: 10px;
        }
        .forecast-item {
            background: rgba(255, 255, 255, 0.2);
            border-radius: 10px;
            padding: 15px;
            min-width: 120px;
            text-align: center;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }
        .forecast-date {
            font-weight: bold;
            margin-bottom: 10px;
        }
        .forecast-temp {
            font-size: 1.2rem;
        }
        .loading {
            text-align: center;
            font-size: 1.2rem;
        }
        .error {
            color: #ff4444;
            text-align: center;
            font-weight: bold;
        }
    </style>
</head>

<body>
<div id="app" class="container">
    <h1 style="text-align: center;">天气预报</h1>

    <div class="search-box">
        <input
                type="text"
                v-model="city"
                placeholder="输入城市名称"
                @keyup.enter="fetchWeather"
        >
        <button @click="fetchWeather">查询</button>
    </div>

    <div v-if="currentWeather" class="current-weather">
        <h2>{{ currentWeather.city }}</h2>
        <div class="current-temp">{{ Math.round(currentWeather.temp) }}°C</div>
        <div>湿度: {{ currentWeather.humidity }}%</div>
        <div>风速: {{ currentWeather.windspeed }} m/s</div>
    </div>

    <h2 v-if="currentWeather.daily">未来7天预报</h2>
    <div class="forecast">
        <div v-for="day in currentWeather.daily" :key="day.date" class="forecast-item">
            <div class="forecast-date">{{ day.date }}</div>
            <div class="forecast-temp">
                最高温度：{{ Math.round(day.day.temphigh) }}°C - 最低温度：{{ Math.round(day.night.templow) }}°C
            </div>
            <div>{{ day.day.weather }}</div>
        </div>
    </div>
</div>

<script>
    const app = {
        data() {
            return {
                city: '',
                currentWeather:{}
            }
        },
        methods:{
            fetchWeather(){
                console.log("fetchWeather")
                axios.get("http://localhost:8080/weather/"+this.city).then(res=>{
                    this.currentWeather = res.data.result
                })
            }
        }
    }
    Vue.createApp(app).mount('#app')
</script>
</body>
</html>
